import request from '@/utils/request'

/**
 * 后边的每次请求都需要携带token
 * @returns {AxiosPromise}
 */
export const findUserList = (current,size,userVO) => {
  return request({
    url:'/user/findUserPage',
    method:'post',
    params:{
      current,
      size
    },
    data:userVO
  })
}

export const findUsers = (username) => {
  return request({
    url:'/user/findUsers',
    method:'get',
    params:{
      username
    }
  })
}

export const findUserById = (userId) => {
  return request({
    url:'/user/findUserById',
    method:'get',
    params: {
      userId
    }
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const findUserByName = (username) => {
  return request({
    url:'/user/findUserByName',
    method:'get',
    params: {
      username
    }
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const saveUser = (addUser) => {
  return request({
    url:'/user/addOrUpdateUser',
    method:'post',
    data:addUser
  })
}

export const resetPasswordBatch = (array) => {
  return request({
    url:'/user/resetPasswordBeatch',
    method:'post',
    data:array
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const deleteUsers = (userId) => {
  return request({
    url:'/user/deleteUserById',
    method:'get',
    params: {
      userId
    }
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const exportUsers = (userVO) => {
  return request({
    url:'/user/exportUsers',
    method:'post',
    data:userVO,
    responseType: "blob"
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const mImportUsers = (formData) => {
  return request({
    url:'/user/ImportUsers',
    method:'post',
    data:formData,
    headers: {
      'Content-Type': 'multipart/form-data',
      // 'Access-Control-Allow-Origin': 'http://127.0.0.1:8080'
      //这里是为了解决跨域问题，但是博主并没有用这种方式解决。后面会给出解决方案
    }
  }).then(res => {
    return res
  },error => {
    return error
  })
}


export const getRolesByUserId = (userId) => {
  return request({
    url:'/userRole/getRolesByUserId',
    method:'get',
    params:{
      userId
    }
  }).then(res => {
    return res
  },error => {
    return error
  })
}

export const getRolesByUserName = (userName) => {
  return request({
    url:'/userRole/getRolesByUserName',
    method:'get',
    params:{
      userName
    },
  }).then(res => {
    return res
  },error => {
    return error
  })
}

